package com.tboss.template.home.service;

import java.security.Principal;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import com.tboss.template.common.springSecurity.SecurityBuildService;

@Service
public class ContextService {

	//private static final Logger logger = LoggerFactory.getLogger(ContextServicer.class);
	
	@Autowired private SecurityBuildService securityBuildService;
	@Value("#{introOption['isConfidential']}") private String isConfidential;
	
	public void index(Locale locale, Model model, Principal principal){
		Date date = new Date();
		DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
		
		String formattedDate = dateFormat.format(date);		
		model.addAttribute("serverTime", formattedDate );		
		if(!Boolean.parseBoolean(isConfidential)) model.addAttribute("guest", this.securityBuildService.setSecurity("guest123"));

		//if(principal != null) logger.info(principal.getName());
	}
	
}
